
#ifndef ATLCIMAGE_IO_H
#define ATLCIMAGE_IO_H

#include <boost/static_assert.hpp>
#include "tstring.h"

#include <boost/gil/extension/io/io_error.hpp>
#include "cimage_io_private.hpp"


namespace boost { namespace gil {

template <typename View>
struct cimage_read_support {
	BOOST_STATIC_CONSTANT(bool,is_supported=
		                  (detail::cimage_read_support_private<typename channel_type<View>::type,
						 								       typename color_space_type<View>::type>::is_supported));
};

template <typename View>
struct cimage_write_support {
    BOOST_STATIC_CONSTANT(bool,is_supported=
                          (detail::cimage_write_support_private<typename channel_type<View>::type,
                                                              typename color_space_type<View>::type>::is_supported));
};

template <typename Image>
inline void cimage_read_image(const tstring& filename, Image& im)
{
	BOOST_STATIC_ASSERT(cimage_read_support<typename Image::view_t>::is_supported);
	detail::cimage_reader m(filename);
	m.read_image(im);
}

template <typename View>
inline void cimage_read_view(const tstring& filename,const View& view) {
    BOOST_STATIC_ASSERT(cimage_read_support<View>::is_supported);
    detail::cimage_reader m(filename);
    m.apply(view);
}

template <typename View>
inline void cimage_png_write_view(const tstring& filename, const View& view) {
	BOOST_STATIC_ASSERT(cimage_write_support<View>::is_supported);
	detail::cimage_writer m(filename);
	m.apply(view, Gdiplus::ImageFormatPNG);
}

template <typename View>
inline void cimage_bmp_write_view(const tstring& filename, const View& view) {
	BOOST_STATIC_ASSERT(cimage_write_support<View>::is_supported);
	detail::cimage_writer m(filename);
	m.apply(view, Gdiplus::ImageFormatBMP);
}

template <typename View>
inline void cimage_gif_write_view(const tstring& filename, const View& view) {
	BOOST_STATIC_ASSERT(cimage_write_support<View>::is_supported);
	detail::cimage_writer m(filename);
	m.apply(view, Gdiplus::ImageFormatGIF);
}

} // gil
} // boost
#endif